#include <stdio.h>
//typedef UINT64 unsigned long long 
#include <stdlib.h>
#include "time.h"

//void  doubletostr(double* a, char* str){
void  floattostr(float* a, char my_str[64]){

	long c;
	c= ((long*)a)[0];
	int i;
	for(i=0;i<32;i++){
               my_str[31-i]=(char)(c&1)+'0';
		c>>=1;
	}
	my_str[32] = '\0';
}

void main (int argc, char **argv)
//void main(void)
{
	//char* str = "11000000000101000000000000000000000000000000000000000000000000000000000000";
	float a = 1.00;
	float b = 1.00;
	float c = 1.00;
	//float max = 10000;
	//float min =-10000;

        float max = atoi(argv[2]);
	float min = atoi(argv[3]);
 

	char  stra[32] ;
	char  strb[32] ;
	char  strc[32] ;
	int i;
	int len ;

	//floattostr(&a,str);
	//printf("float is %lf \n", a );
	//printf("float is %s\n", str );

   	FILE * fpw_floata = fopen("floatma.txt", "w");
   	FILE * fpw_floatb = fopen("floatmb.txt", "w");
   	FILE * fpw_floatc = fopen("floatmc.txt", "w");
   	FILE * fpw_bina   = fopen("float_binma.txt", "w");
   	FILE * fpw_binb   = fopen("float_binmb.txt", "w");
   	FILE * fpw_binc   = fopen("float_binmc.txt", "w");
    	srand(time(0));
        len = atoi(argv[1]);
        
	for (i=0;i<=len;i++){
		//a=i;
		a = min+1.0*rand()/RAND_MAX *(max-min);
		b = min+1.0*rand()/RAND_MAX *(max-min);
		c = a * b ;
		floattostr(&a,stra);
		floattostr(&b,strb);
		floattostr(&c,strc);
		printf("float is %lf * %lf = %lf   \n", a , b, c );
		//printf("float is %s\n", str );
		//fputs(stra,fpw_bina);
		//fputs(strb,fpw_binb);
		//fputs(strc,fpw_binc);
		fprintf(fpw_bina,"%32.32s",stra);
		fprintf(fpw_binb,"%32.32s",strb);
		fprintf(fpw_binc,"%32.32s",strc);

		fprintf(fpw_floata,"%f",a);
		fprintf(fpw_floatb,"%f",b);
		fprintf(fpw_floatc,"%f",c);
		fputs("\n",fpw_bina);
		fputs("\n",fpw_binb);
		fputs("\n",fpw_binc);
		fputs("\n",fpw_floata);
		fputs("\n",fpw_floatb);
		fputs("\n",fpw_floatc);
	}
	fclose(fpw_bina);
	fclose(fpw_binb);
	fclose(fpw_binc);
	fclose(fpw_floata);
	fclose(fpw_floatb);
	fclose(fpw_floatc);
}
